<?php

namespace App\Jobs;

use App\Datalog\Events\RegisterEventLog;
use App\Datalog\Users\RegisterUserSet;
use App\Models\Users;
use App\Services\AdPostbackService;
use App\Services\FirstupService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class UserRegQueue implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    use TraitQueue;

    protected $userId;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($user_id)
    {
        $this->userId = $user_id;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $user = Users::find($this->userId);

        // 数据落地
        RegisterEventLog::getInstance()->addLog($user);
        RegisterUserSet::getInstance()->addSet($user);

        // 进行一次激活匹配
        FirstupService::getInstance()->handleUserFirstup($user);

        // 进行一次买量回传
        AdPostbackService::getInstance()->postbackReg($user);
    }
}
